﻿using Helper;
using Helper.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Starehe.Testing
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            Progress<ProgressReport> report = new Progress<ProgressReport>();
            report.ProgressChanged += (o, ex) =>
                {
                    progress.Text = ex.Percentage;
                };
            this.DataContext = await GetDataP(5000, "StudentID",
                report);
        }

        private Task<ObservableCollection<StudentModel>> GetDataP(decimal d, string uid, Progress<ProgressReport> report)
        {
            return Task.Run<ObservableCollection<StudentModel>>(() =>
                {
                    return GenerateData.GetData<StudentModel>(d, uid,
                report);
                });
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private async void Button_Click_2(object sender, RoutedEventArgs e)
        {
            ObservableCollection<StudentModel> studs = (ObservableCollection<StudentModel>)this.DataContext;
            decimal d = 0;
            decimal tot = studs.Count;
            foreach (StudentModel st in studs)
            {
                d++;
                await DatabaseClasses.SaveNewStudentAsync(st);
                progress.Text = ((d * 100) / tot).ToString();
            }
        }
    }

    public class ProgressReport
    {
        public string Percentage { get; set; }
        public ProgressReport()
        { }
        public ProgressReport(string percentage)
        { Percentage = percentage; }
    }
}
